<template>
  <div class="app-container">
    <div v-show="!modifyInfo.visible && !detailInfo.visible">
      <!-- 条件栏 -->
      <div class="filter-wrapper">
        <NewPageFilter
          ref="pageFilter"
          v-model:query="filterInfo.query.queryMap"
          :query-more-json="true"
          :filter-list="filterInfo.searchList"
          :filter-btn="filterInfo.searchBtn"
          :clear-type="clearType"
          :slip-select-request="slipSelectRequest"
        >
        </NewPageFilter>
      </div>

      <div class="filter-wrapper">
        <NewPageFilter :filter-btn="filterInfo.btList">
          <template v-slot:filter-print>
            <el-button :disabled="!canPrint" @click="print()">打印</el-button>
          </template>
          <template v-slot:filter-excel>
            <el-button :disabled="!canExcel" @click="exportExcel()"
              >导出excel</el-button
            >
          </template>
        </NewPageFilter>
        <div class="display-flex">
          <Group-select
            :options="groupSelectInfo.options"
            v-model:selections="groupSelectInfo.selections"
            @callback="groupSelect"
            @callbackVal="updateGroupSelections"
          ></Group-select>
          <el-button @click="preferenceInfo.visible = true">偏好设置</el-button>
        </div>
      </div>
      <!-- 表格 -->
      <table-container
        v-if="groupFlag"
        class="groupFlag-container"
        :is-group-search="true"
        v-model:data="groupSelectInfo.data"
        :field-list="tableInfo.fieldList"
        :check-box="false"
        :tab-index="false"
        :pager="false"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        :span-method="arraySpanMethod"
        :row-class-name="tableRowClassName"
        @exChange="exChange"
        @sortChange="sortChange"
        @handleEvent="handleEvent"
      >
        <template v-slot:col-orderNo="scope">
          <p class="slip-edit" @click="showProductDetail(scope.row)">
            {{ scope.row.orderNo || '-' }}
          </p>
        </template>
      </table-container>
      <!-- 表格 -->
      <table-container
        v-else
        :refresh="tableInfo.refresh"
        :init-curpage="tableInfo.initCurpage"
        v-model:data="tableInfo.data"
        :api="tableInfo.api"
        :tab-index="false"
        :check-box="true"
        :query="filterInfo.query"
        :field-list="tableInfo.fieldList"
        :handle="tableInfo.handle"
        :row-class-name="tableRowOtherClassName"
        @pageInfo="pageInfo"
        @handleEvent="handleEvent"
      >
        <template v-slot:col-orderNo="scope">
          <p class="slip-edit" @click="showProductDetail(scope.row)">
            {{ scope.row.orderNo || '-' }}
          </p>
        </template>
      </table-container>
    </div>
    <!-- 新增或修改 -->
    <deviceMaintenanceTask-modify
      v-if="modifyInfo.visible"
      :id="modifyInfo.id"
      v-model:visible="modifyInfo.visible"
      :title="modifyInfo.title"
      @returnModify="returnModify"
    />

    <!-- 详情页 -->
    <deviceMaintenanceTask-detail
      v-if="detailInfo.visible"
      :id="detailInfo.id"
      v-model:visible="detailInfo.visible"
      :title="detailInfo.title"
      @returnBack="getList"
    />

    <SetPreference
      v-if="preferenceInfo.visible"
      v-model:visible="preferenceInfo.visible"
      :search-list="filterInfo.searchList"
      :field-list="tableInfo.fieldList"
      :customize-user-v-o="filterInfo.query.customizeUserVO"
      @callback="setPreferenceCallback"
    />
    <advanced-search
      v-if="advancedSearchInfo.visible"
      v-model:visible="advancedSearchInfo.visible"
      :field-list="tableInfo.fieldList"
      v-model:form-data="advancedSearchInfo.data"
      @callback="advancedSearchCallback"
    />
    <TurnOver
      v-if="turnOverInfo.visible"
      v-model:visible="turnOverInfo.visible"
      :row="turnOverInfo.row"
      @callbackTurnOver="callbackTurnOver"
    />
    <MountingsUse
      v-if="mountingsUseInfo.visible"
      v-model:visible="mountingsUseInfo.visible"
      :row="mountingsUseInfo.row"
      @callbackMountingsUse="callbackMountingsUse"
    />
    <HandleMaintenance
      v-if="handleMaintenanceInfo.visible"
      v-model:visible="handleMaintenanceInfo.visible"
      :row="handleMaintenanceInfo.row"
      @callbackHandleMaintenance="callbackHandleMaintenance"
    />
    <Finish
      v-if="finishInfo.visible"
      v-model:visible="finishInfo.visible"
      :row="finishInfo.row"
      @callbackFinish="callbackFinish"
    />
    <chose-printer
      :visible="printerInfo.visible"
      @callBack="handlePrinterCallBack"
    />
    <page-dialog
      v-show="dialogInfo.visible"
      :title="dialogInfo.title"
      v-model:visible="dialogInfo.visible"
      :width="dialogInfo.width"
      :bt-loading="dialogInfo.btLoading"
      :bt-list="dialogInfo.btList"
    >
      <div class="asset-msg">
        <div class="asset-msg-label">
          <i class="el-icon-warning"></i>{{ dialogInfo.msg }}：
        </div>
        <el-radio-group v-model="dialogInfo.flag">
          <el-radio :label="true">当前页数据</el-radio>
          <el-radio :label="false">全部页数据</el-radio>
        </el-radio-group>
      </div>
    </page-dialog>
  </div>
</template>

<script setup name="deviceMaintenanceTask">
import {
  excelDeviceMaintenanceTask,
  printDeviceMaintenanceTask,
  workDeviceMaintenanceTask,
  getDeviceMaintenanceTaskCustomizeListPage,
  getDeviceMaintenanceTaskCustomizeGroups,
  cancelDeviceMaintenanceTask,
  deleteTaskById,
} from '@/api/repair.js'
import { getCustomizeSetting, updateUserCustomize } from '@/api/customize'
import { ElMessage } from 'element-plus'
import PageDialog from '@/components/PageDialog/index'
import chosePrinter from '@/components/ChosePrinter'
import DeviceMaintenanceTaskModify from '@/views/repair/repairManage/deviceMaintenanceTask/modify.vue'
import DeviceMaintenanceTaskDetail from '@/views/repair/repairManage/deviceMaintenanceTask/detail.vue'
import TurnOver from '@/views/repair/repairManage/deviceMaintenanceTask/turnOver.vue'
import MountingsUse from '@/views/repair/repairManage/deviceMaintenanceTask/mountingsUse.vue'
import Finish from '@/views/repair/repairManage/deviceMaintenanceTask/finish.vue'
import HandleMaintenance from '@/views/repair/repairManage/deviceMaintenanceTask/handleMaintenance.vue'
import { getAssetCardAll } from '@/api/core'
import { fatchTemplateByCode } from '@/api/base'

import { getDepotAll } from '@/api/core'

const { proxy } = getCurrentInstance()
const emit = defineEmits()

const TableContainer = defineAsyncComponent(() =>
  import('@/components/TableContainer/index')
)

const GroupSelect = defineAsyncComponent(() =>
  import('@/components/GroupSelect/index')
)
const SetPreference = defineAsyncComponent(() =>
  import('@/components/SetPreference/defaultSetPreference')
)
const AdvancedSearch = defineAsyncComponent(() =>
  import('@/components/AdvancedSearch/index')
)

const props = defineProps(['query'])

const storeState = proxy.$store.state
const clearType = ref(true)
const slipSelectRequest = ref(true)
const groupFlag = ref(false)
const productionTimePickerOptions = ref({})

const printerInfo = reactive({
  visible: false,
  data: {},
})
const dialogInfo = reactive({
  visible: false,
  title: '提示',
  btLoading: false,
  type: '',
  msg: '',
  width: '400px',
  flag: true,
  btList: [
    { label: '关闭', event: handleClose, show: true },
    {
      label: '打印',
      type: 'primary',
      event: checkConfirm,
      show: true,
    },
  ],
})
const turnOverInfo = reactive({
  visible: false,
  row: {},
})
const mountingsUseInfo = reactive({
  visible: false,
  row: {},
})
const handleMaintenanceInfo = reactive({
  visible: false,
  row: {},
})
const finishInfo = reactive({
  visible: false,
  row: {},
})

// 过滤相关配置
const groupSelectInfo = reactive({
  options: [],
  selections: [],
  data: [],
})
const listTypeInfo = reactive({
  typeList: [],
})
const filterInfo = reactive({
  query: {
    sortString: '',
    customizeUserVO: {},
    queryMap: {},
    queryParams: {},
  },
  searchList: [],
  searchBtn: [
    { type: 'button', label: '搜索', event: search },
    { type: 'button', label: '高级查询', event: advancedSearchShow },
    { type: 'button', label: '重置', event: clearSearch },
  ],
  btList: [
    {
      type: 'button',
      label: '新增',
      event: create,
      show: proxy.$permission('deviceMaintenanceTask:add'),
    },
    {
      type: 'slot',
      value: 'excel',
      show: proxy.$permission('deviceMaintenanceTask:excel'),
    },
    {
      type: 'slot',
      value: 'print',
      show: proxy.$permission('deviceMaintenanceTask:print'),
    },
  ],
})

const tableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  data: [],
  api: undefined,
  selections: [],
  fieldList: [],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '修改',
        event: update,
        show: proxy.$permission('deviceMaintenanceTask:update'),
        ifRender: function (row) {
          return (
            row.status === 1 &&
            row.maintenancePlanOrderNo == null &&
            row.maintenancePrincipal === storeState.user.userInfo.user.id
          )
        },
      },
      {
        label: '删除',
        event: remove,
        show: proxy.$permission('deviceMaintenanceTask:delete'),
        ifRender: function (row) {
          return (
            row.status === 1 &&
            row.maintenancePlanOrderNo == null &&
            row.maintenancePrincipal === storeState.user.userInfo.user.id
          )
        },
      },
      {
        label: '接单',
        event: receiveOrder,
        show: proxy.$permission('deviceMaintenanceTask:receiveOrder'),
        ifRender: function (row) {
          return (
            row.status === 1 &&
            row.maintenanceOrgId === undefined &&
            row.maintenancePrincipal === storeState.user.userInfo.user.id
          )
        },
      },
      {
        label: '转交',
        event: turnOver,
        show: proxy.$permission('deviceMaintenanceTask:turnOver'),
        ifRender: function (row) {
          return (
            (row.status === 1 || row.status === 2) &&
            row.maintenanceOrgId === undefined &&
            row.maintenancePrincipal === storeState.user.userInfo.user.id
          )
        },
      },
      // {
        // label: '配件使用',
        // event: mountingsUse,
        // show: proxy.$permission('deviceMaintenanceTask:mountingsUse'),
        // ifRender: function (row) {
          // return (
            // row.status === 2 &&
            // row.maintenanceOrgId === undefined &&
            // row.maintenancePrincipal === storeState.user.userInfo.user.id
          // )
        // },
      // },
      // {
        // label: '养护执行',
        // event: handleMaintenance,
        // show: proxy.$permission('deviceMaintenanceTask:handleMaintenance'),
        // ifRender: function (row) {
          // return (
            // row.status === 2 &&
            // row.maintenanceOrgId === undefined &&
            // row.maintenancePrincipal === storeState.user.userInfo.user.id
          // )
        // },
      // },
      {
        label: '执行',
        event: _finish,
        show: proxy.$permission('deviceMaintenanceTask:handleMaintenance'),
        ifRender: function (row) {
          return (
            row.status === 2 &&
            row.maintenanceOrgId === undefined &&
            row.maintenancePrincipal === storeState.user.userInfo.user.id
          )
        },
      },
      {
        label: '取消',
        popconfirmText: '取消后将改变数据,是否继续？',
        event: cancel,
        show: proxy.$permission('deviceMaintenanceTask:cancel'),
        ifRender: function (row) {
          return (
            (row.status === 1 || row.status === 2) &&
            row.maintenanceOrgId === undefined &&
            row.maintenancePrincipal === storeState.user.userInfo.user.id
          )
        },
      },
    ],
  },
})
const detailListInfo = reactive({
  visible: false,
})
//明细相关
const detailInfo = reactive({
  visible: false,
  title: '养护任务详情',
  id: '',
})
//新增或更新相关
const modifyInfo = reactive({
  visible: false,
  title: '',
  id: '',
})
const preferenceInfo = reactive({
  visible: false,
})
const advancedSearchInfo = reactive({
  visible: false,
  data: {},
})
let page = reactive({
  page: true,
  curPage: 1, // 当前页
  pageSize: 20, // 每页条数
})
//选择维修人员
const selectRepairUserInfo = reactive({
  visible: false,
  saveEmpty: true,
  query: {
    // idNotIn: "",
  },
})

const canReminder = computed(() => {
  return (
    tableInfo.selections.length &&
    !tableInfo.selections.filter(
      (item) => item.status !== 1 && item.status !== 2 && item.status !== 3
    ).length
  )
})
const canPrint = computed(() => {
  return !groupFlag.value
})
const canExcel = computed(() => {
  return !groupFlag.value
})
const toPage = computed(() => {
  return proxy.$store.state.settings.toPage
})

let stopWatch = function() {}
onActivated(() => {
  stopWatch = watch(
    () => toPage.value,
    (val) => {
      if (val) {
        let menus = proxy.$store.state.permission.defaultMenus
        menus.forEach((item) => {
          if (item.children) {
            item.children.forEach((el) => {
              if (el.code === 'deviceMaintenanceTask' && el.url === val.url) {
                detailInfo.visible = false
                turnOverInfo.visible = false
                finishInfo.visible = false
                handleMaintenanceInfo.visible = false
                mountingsUseInfo.visible = false
                printerInfo.visible = false
                advancedSearchInfo.visible = false
                preferenceInfo.visible = false
                dialogInfo.visible = false
                if (val.urlType === 1) {
                  getList()
                } else if (val.urlType === 2) {
                  detailInfo.visible = true
                  detailInfo.id = val.businessId
                  sessionStorage.setItem('storeRowId', val.businessId)
                }
                proxy.$store.dispatch('settings/toPage', '')
              }
            })
          }
        })
      }
    },
    {
      deep: true,
      immediate: true,
    }
  )
})
onDeactivated(() => {
  stopWatch()
})

let obj = {
  assetName: {
    label: '资产名称',
    value: 'assetName',
    componentType: 'input',
    show: false,
    type: 'column',
    hidden: true,
  },
  typeValue: {
    label: '养护类型',
    value: 'typeValue',
    asValue: 'type',
    componentType: 'select-model',
    code: 'device_maintenance_type',
    show: false,
    hidden: true,
  },
  statusValue: {
    label: '状态',
    value: 'statusValue',
    asValue: 'status',
    componentType: 'select-model',
    code: 'device_maintenance_kind',
    show: false,
    hidden: true,
  },
  maintenancePlanOrderNo: {
    label: '养护计划编码',
    value: 'maintenancePlanOrderNo',
    componentType: 'input',
    show: false,
    type: 'column',
    hidden: true,
  },
  completeDate: {
    label: '完工时间',
    value: 'completeDate',
    componentType: 'input',
    show: false,
    type: 'column',
    hidden: true,
  },
  depotName: {
    label: '出库仓库',
    value: 'depotName',
    asValue: 'depotId',
    componentType: 'slip-select',
    query: {
      depotAuth: 'id',
      status: 1,
      useTypeId: '2',
    },
    api: getDepotAll,
    show: false,
    hidden: true,
  },
}
tableInfo.fieldList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...proxy.$fn.deepClone(obj),
})
filterInfo.searchList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...proxy.$fn.deepClone(obj),
})
getCustomize()

//取消
function cancel(row) {
  cancelDeviceMaintenanceTask(row.id).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//接单
function receiveOrder(row) {
  workDeviceMaintenanceTask(row.id).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//转交
function turnOver(row) {
  turnOverInfo.visible = true
  turnOverInfo.row = row
}
function callbackTurnOver() {
  turnOverInfo.visible = false
  getList()
}
function handleMaintenance(row) {
  handleMaintenanceInfo.visible = true
  handleMaintenanceInfo.row = row
}
function callbackHandleMaintenance() {
  handleMaintenanceInfo.visible = false
  getList()
}
//配件使用
function mountingsUse(row) {
  mountingsUseInfo.visible = true
  mountingsUseInfo.row = row
}
function callbackMountingsUse() {
  mountingsUseInfo.visible = false
  getList()
}
//完工
function _finish(row) {
  finishInfo.visible = true
  finishInfo.row = row
}
function callbackFinish() {
  finishInfo.visible = false
  getList()
}
// 编辑
function update(row) {
  sessionStorage.setItem('storeRowId', row.id)
  modifyInfo.id = row.id
  modifyInfo.visible = true
  modifyInfo.title = '修改养护任务'
}
// 删除
function remove(row) {
  deleteTaskById(row.id).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
// 创建
function create() {
  modifyInfo.visible = true
  modifyInfo.title = '新增养护任务'
  modifyInfo.id = null
}
function showProductDetail(row) {
  sessionStorage.setItem('storeRowId', row.id)
  detailInfo.visible = true
  detailInfo.title = '养护任务详情'
  detailInfo.id = row.id
}
function tableRowOtherClassName({ row }) {
  let rowId = sessionStorage.getItem('storeRowId')
  if (rowId && row.id === Number(rowId)) {
    return 'check-row'
  }
  return ''
}
function returnModify() {
  if (modifyInfo.id) {
    getList()
  } else {
    search()
  }
}
function pageInfo(obj) {
  page = obj
}

function updateGroupSelections(arr) {
  filterInfo.query.groups = arr
  groupSelectInfo.selections = arr
  if (!arr.length) {
    filterInfo.query.groups = []
    filterInfo.query.groupMap = {}
    groupSelectInfo.data = []
    groupFlag.value = false
  }
}
function groupSelect(arr) {
  if (arr.length) {
    //点击分组
    groupFlag.value = true
    filterInfo.query.groups = arr
    groupSelectInfo.selections = arr
    getCustomizeGroupsList()
  } else {
    ElMessage.warning({
      message: '请选择分组条件！',
      showClose: true,
      duration: 3000,
    })
  }
}

async function getCustomizeGroupsList(len, param, expande) {
  //分组查询
  let params = {}
  if (len) {
    params = param
  } else {
    params = filterInfo.query
  }
  if (filterInfo.query.queryDtoList && filterInfo.query.queryDtoList.length) {
    params = proxy.$fn.deepClone(params)
    params.queryMap = {}
  }
  await getDeviceMaintenanceTaskCustomizeGroups(params).then(async (res) => {
    if (res && res.success) {
      let data = res.data
      let newData = []
      if (len) {
        await data.forEach((item, index) => {
          newData.push({
            ...item,
            id: index + Math.random(),
            isColspan: true,
            children: [{ ...item, id: index + Math.random(), isColspan: true }],
          })
        })
        expande.children = newData
      } else {
        await data.forEach((item, index) => {
          newData.push({
            ...item,
            id: index + Math.random(),
            isColspan: true,
            children: [{ id: index + Math.random(), isColspan: true }],
          })
        })
        groupSelectInfo.data = newData
      }
    }
  })
}
function exChange(data, expandedRows) {
  //展开分组
  if (expandedRows) {
    let len = data.nextGroups.length
    if (len) {
      let params = {
        ...filterInfo.query,
        groups: data.nextGroups,
        groupMap: { ...data.query },
        queryMap: { ...filterInfo.query.queryMap, ...data.query },
      }
      getCustomizeGroupsList(len, params, data)
    } else {
      let params = {
        ...filterInfo.query,
        groups: [],
        groupMap: {},
        queryMap: { ...filterInfo.query.queryMap, ...data.query },
      }
      getAssetCardAll(params).then(async (res) => {
        if (res && res.success) {
          let resData = res.data
          await resData.forEach((item, index) => {
            item.id = index + Math.random()
            item.isColspan = false
          })
          data.children = resData
        }
      })
    }
  } else {
    data.children = [{ id: Math.random(), isColspan: true }]
  }
}

function setPreferenceCallback(obj) {
  updateUserCustomize(obj.customizeUserVO).then((res) => {
    if (res && res.success) {
      getCustomize(!slipSelectRequest.value)
    }
  })
}
function advancedSearchShow() {
  advancedSearchInfo.visible = true
}
async function advancedSearchCallback(obj) {
  filterInfo.query.queryMap = {}
  let arr = [
    {
      asTbName: 'repair_order',
      columnName: 'repair_dept_id',
      queryType: 'IN',
      queryCategory: 'AND',
      value: 'deptAuth',
    },
  ]
  filterInfo.query.queryDtoList = [...obj.queryDtoList, ...arr]
  advancedSearchInfo.data = obj.data
  if (groupSelectInfo.selections.length > 0) {
    await getCustomizeGroupsList()
  } else {
    groupSelectInfo.data = []
    await getList()
  }
  filterInfo.query.queryMap = proxy.$fn.deepClone(filterInfo.copyQueryMap)
  clearType.value = !clearType.value
}
async function getList() {
  tableInfo.refresh = Math.random()
}
function search() {
  advancedSearchInfo.data = {}
  filterInfo.query.queryDtoList = []
  if (groupSelectInfo.selections.length > 0) {
    getCustomizeGroupsList()
  } else {
    groupSelectInfo.data = []
    tableInfo.initCurpage = Math.random()
    tableInfo.refresh = Math.random()
  }
}
function handleEvent(event, data) {
  switch (event) {
    case 'tableCheck':
      tableInfo.selections = [...data]
      break
  }
}
function clearSearch() {
  clearType.value = !clearType.value
  filterInfo.query.queryMap = proxy.$fn.deepClone(filterInfo.copyQueryMap)
  search()
}
function getCustomize(_slipSelectRequest = true) {
  let param = {
    tableKey:
      'deviceMaintenanceTaskList-com.slip.spd.entity.vo.device.maintenance.task.DeviceMaintenanceTaskVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.query.customizeUserVO = data
      tableInfo.fieldList = proxy.$fn.setFieldList(
        tableInfo.fieldList,
        data.detail
      )
      let searchInfo = proxy.$fn.setSearchList(
        filterInfo.searchList,
        data.detail
      )
      let tableFieldInfo = proxy.$fn.setFieldList(
        tableInfo.fieldList,
        data.detail,
        true
      )

      // tableInfo.fieldList = tableFieldInfo.fieldList
      groupSelectInfo.options = tableFieldInfo.groupOption
      filterInfo.query.queryMap = {
        ...filterInfo.query.queryMap,
        ...searchInfo.queryMap,
      }
      filterInfo.copyQueryMap = proxy.$fn.deepClone(filterInfo.query.queryMap)
      filterInfo.searchList = searchInfo.searchList
      filterInfo.searchList.forEach((item) => {
        item.event = search
      })
      slipSelectRequest.value = _slipSelectRequest
      tableInfo.api = getDeviceMaintenanceTaskCustomizeListPage
      getList()
    }
  })
}
function sortChange(column) {
  if (filterInfo.query.customizeUserVO.head.sortType === 0) {
    let arr = proxy.$fn.sortChange(column, filterInfo.sortArr)
    filterInfo.sortArr = arr
    filterInfo.query.sortString = arr.toString()
    getList()
  }
}
function tableRowClassName(row) {
  let rowId = sessionStorage.getItem('storeRowId')
  if (rowId && row.id === Number(rowId)) {
    return 'check-row'
  } else if (row.row.nextGroups) {
    return 'bg-color-EBEEF5'
  } else {
    return ''
  }
}
function arraySpanMethod({ row, columnIndex }) {
  if (row.nextGroups) {
    if (columnIndex === 0) {
      return {
        rowspan: 1,
        colspan: tableInfo.fieldList.length,
      }
    }
  }
}

function handlePrinterCallBack(printer) {
  if (printer !== false) {
    proxy.$print.buildRenderBarCode(printerInfo.data, printer)
  }
  printerInfo.visible = false
}
function handleClose() {
  dialogInfo.visible = false
}
function checkConfirm() {
  if (dialogInfo.type === 'excel') {
    exportExcelList()
  } else if (dialogInfo.type === 'print') {
    printList()
  }
  dialogInfo.visible = false
  dialogInfo.msg = ''
}
function exportExcel() {
  dialogInfo.visible = true
  dialogInfo.type = 'excel'
  dialogInfo.msg = '请选择数据导出范围'
  dialogInfo.btList[1].label = '导出'
  dialogInfo.flag = true
}
function exportExcelList() {
  let params = {
    ...filterInfo.query,
    ...page,
    page: dialogInfo.flag,
  }
  excelDeviceMaintenanceTask(params).then((resp) => {
    if (resp) {
      proxy.$fn.parseExcel(resp)
    }
  })
}

async function print() {
  dialogInfo.visible = true
  dialogInfo.type = 'print'
  dialogInfo.msg = '请选择当数据打印范围'
  dialogInfo.btList[1].label = '打印'
  dialogInfo.flag = true
}

function printList() {
  fatchTemplateByCode({
    resourceCode: 'deviceMaintenanceTask:print',
    isDefault: 1,
  }).then((res) => {
    if (res && res.success) {
      let temp = proxy.$fn.getPrintTemp(res.data[0])
      getPrintData(temp, dialogInfo.flag)
    }
  })
}
function getPrintData(temp, flag) {
  let query = {
    customizeDto: filterInfo.query,
  }
  let params = {
    ...query,
    ...page,
    page: flag,
  }
  printDeviceMaintenanceTask(params).then((res) => {
    if (res.success && res) {
      let data = proxy.$fn.deepClone(res.data)
      let newData = data.map((item) => {
        return {
          ...item,
          ...item.orderInfo,
        }
      })
      proxy.$lodop.preview(temp, newData)
    }
  })
}
</script>

<style scoped></style>
